

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#include "common/utils.hpp"

// 在每个树（二叉树）行中找最大值
std::vector<int> largestValues(TreeNode* root) {
    std::vector<int> result;
    std::queue<TreeNode*> queue;

    if (root != nullptr) queue.push(root);

    while (!queue.empty()) {
        int size = queue.size();
        int max = INT_MIN;
        for (int i = 0; i < size; i++) {
            TreeNode* node = queue.front();
            queue.pop();
            if (node->val > max) max = node->val;

            if (node->left) queue.push(node->left);
            if (node->right) queue.push(node->right);
        }
        result.push_back(max);
    }

    return result;
}

extern TreeNode* commonRoot;

int main() {
    std::vector<int> res = largestValues(commonRoot);
    std::cout << "largestValues: \n";
    printVector(res);
}